//
// Created by EDY on 24-11-3.
//

#ifndef MYSQLMANAGER_H
#define MYSQLMANAGER_H

//#pragma once
#include <iostream>
#include "mysql.h"
#include <map>
using namespace std;

struct Friend{
    int id;
    char name[20];
    char phone[20];
    char address[20];
};

class MysqlManager{
private:
    MYSQL *m_Mysql = new MYSQL();
    MYSQL_RES* m_SelectResult;

public:
    const char* m_host;
    const char* m_username;
    const char* m_password;
    const char* m_database;
    unsigned int m_port;
    const char* m_unix_socket;
    unsigned long m_clientflag;

    bool init();
    void freeConnect();
    bool runSql(const char* sql);
    bool selectData(const char* sql);
    map<string, Friend> loadContact();
    void saveContact(const map<string, Friend>& contact);
};


#endif //MYSQLMANAGER_H
